Skip to content

fix: cascade-remove inactive descendants when deleting archived workspaces - #3982

Closed
ethanndickson wants to merge 5 commits into
mainfrom
fix/archived-workspace-shift-delete
Closed

fix: cascade-remove inactive descendants when deleting archived workspaces#3982
ethanndickson wants to merge 5 commits into
mainfrom
fix/archived-workspace-shift-delete

Conversation

@ethanndickson

Copy link
Copy Markdown
Member

Summary

Shift+click to bypass the force-delete modal on archived workspaces stopped working after the persistent sub-agent lifecycle change (PR #3825).

Root Cause

removeUnlocked had a guard using hasDescendantAgentTasks() that checks for any descendants (active or inactive) and fires before the force flag is even evaluated. Since PR #3825 made completed sub-agents persist as inactive children in config, any workspace that ever spawned a sub-agent could never be deleted — shift+click bypass, force delete, and normal delete all hit this guard.

Fix

  • Guard: Changed from hasDescendantAgentTaskshasActiveDescendantAgentTasksForWorkspace — only blocks deletion when children are actively running (queued/starting/running)
  • Cascade removal: Before removing the parent, cascade-remove all inactive descendants deepest-first via removeUnlocked(childId, true). This mirrors what task_remove requires users to do manually but happens automatically during workspace deletion
  • New method: Added listDescendantAgentTaskIdsDeepestFirst() to TaskService for the cascade ordering

What this fixes

  • Shift+click delete on archived workspaces works again (skips force-confirm modal)
  • Regular and bulk delete on archived workspaces with finished sub-agents works again
  • Active sub-agents still correctly block parent deletion

Risks

Low — the safe default (block on active descendants) is preserved. Only inactive (reported/interrupted) descendants are cascade-removed, and each child removal goes through the full removeUnlocked path including all cleanup steps.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3eeef7a926

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/services/workspaceService.ts Outdated
Comment thread src/node/services/workspaceService.ts Outdated
Comment thread src/node/services/workspaceService.ts Outdated
Comment thread src/node/services/workspaceService.ts Outdated
Comment thread src/node/services/workspaceService.ts Outdated
Comment thread src/node/services/workspaceService.ts Outdated
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 5bda4fa207

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

This comment has been minimized.

@ethanndickson
ethanndickson force-pushed the fix/archived-workspace-shift-delete branch from 5bda4fa to 7da5387 Compare August 27, 2026 09:21

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7da5387e1b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/services/taskService.ts Outdated
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

3 similar comments
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 8111f648a5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 8111f648a5

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ethanndickson
ethanndickson force-pushed the fix/archived-workspace-shift-delete branch from 8111f64 to cc9f32a Compare September 3, 2026 18:31
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-04T07:58:47.303969Z 58448dd New commits
🔒 Security Review Completed 2026-09-04T08:00:52.968143Z 58448dd New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…paces

The persistent sub-agent lifecycle change (PR #3825) made completed
sub-agents persist in config as inactive children. But removeUnlocked's
guard used hasDescendantAgentTasks() which checks for ANY descendants
(active or inactive), and fires before the force flag is checked. This
meant any workspace that ever spawned a sub-agent could never be deleted
— shift+click bypass, force delete, and normal delete all failed.

Fix:
- Change the guard to hasActiveDescendantAgentTasksForWorkspace so only
  running/queued children block deletion
- Cascade-remove inactive descendants deepest-first before removing the
  parent, mirroring what task_remove requires users to do manually
- Add listDescendantAgentTaskIdsDeepestFirst() to TaskService for the
  cascade ordering
Address Codex review comments by replacing the inline cascade loop in
WorkspaceService.removeUnlocked() with a dedicated TaskService method
(cascadeRemoveInactiveDescendantsWhileTaskTreeLocked) that includes:

- Git-patch-artifact lock + wait before removal (comment #3)
- Ownership tombstone persistence (comment #6)
- Force-flag passthrough from parent instead of hardcoding true (comment #1)
- Active/streaming safety checks per descendant

The new method is designed to run inside an already-held task-tree lifecycle
lock, avoiding deadlock by calling removeWhileTaskTreeLocked directly.
@ethanndickson
ethanndickson force-pushed the fix/archived-workspace-shift-delete branch from cc9f32a to 58448dd Compare September 4, 2026 07:56
@ethanndickson

Copy link
Copy Markdown
Member Author

Closing as superseded by #4171 ("[workspace] 🤖 Fix deletion of parents with inactive descendants", 50b357e67, merged 2026-09-09).

Why

#4171 fixes the same root cause — the hasDescendantAgentTasks guard in removeUnlocked blocking deletion of any workspace that ever spawned a sub-agent — but routes descendant removal through explicit user consent rather than an automatic cascade.

The pieces this PR added now exist on main in consented form:

This PR On main
listDescendantAgentTaskIdsDeepestFirst() listWorkspaceRemovalDescendants() (taskService.ts)
cascadeRemoveInactiveDescendantsWhileTaskTreeLocked() removeAcknowledgedDescendantsWhileTaskTreeLocked() (taskService.ts)
Inlined safeguards (patch-generation wait, tombstones, streaming check) removeInactiveDescendantAgentTaskWhileTaskTreeLocked() (taskService.ts)

The reported symptom is resolved

Shift+click delete on an archived workspace with inactive descendants works again. The first remove() fails, the backend attaches the descendant list to the error, and the UI opens ForceDeleteModal pre-seeded with that scope; the user confirms with Y.

One deliberate difference from this PR's approach: shift+click no longer skips confirmation when descendants exist. That is intentional — see the comment in ArchivedWorkspaces.tsx ("Descendant deletion always requires an explicit scope confirmation, including Shift-click") and taskService.ts ("Force does not grant consent to stop children"). Covered by ArchivedWorkspaces.test.tsx.

Why this branch was not rebased

main has moved 96 commits ahead of this branch's merge base, with textual conflicts in workspaceService.ts and workspaceService.test.ts. More importantly, both possible resolutions are unattractive:

  • Guard swap only (drop the cascade, keep hasActiveDescendantAgentTasksForWorkspace) would let remove(parent, force) with no acknowledgedDescendantIds delete a parent while leaving inactive descendants orphaned in config with a dangling parentWorkspaceId. Nothing reaps them: there is no orphan pruning in src/node/config/index.ts, the rootWorkspaceId walk assigns a deleted parent as root, and persistRemovedAgentTaskTombstones writes into ancestor session dirs that parent removal has already destroyed.
  • Keep the full cascade would delete descendants with no consent, contradicting the model [workspace] 🤖 Fix deletion of parents with inactive descendants #4171 established — and re-introducing the concern Codex originally raised here as P1 ("Honor non-force deletion for cascaded descendants").

No residual bug remains for this PR to fix. If the extra confirmation proves annoying for inactive-only descendants, the right follow-up is a small frontend change in handleDelete to auto-acknowledge when every descendant is inactive — not a revival of this branch.


Generated with xum • Model: anthropic:claude-opus-5 • Thinking: xhigh • Cost: $1.70

@ethanndickson

Copy link
Copy Markdown
Member Author

Superseded by #4171. See the rationale above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant